package com.dw.common.bean;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class NetNode {
    private String ip;

    private int port;

    private int taskCounts;

    public static NetNode stringToNetNode(String str) {
        if (StringUtils.isBlank(str)) {
            return null;
        }
        String[] strings = str.split(":");
        NetNode node = new NetNode();
        node.setIp(strings[0]);
        node.setPort(Integer.parseInt(strings[1]));
        node.setTaskCounts(Integer.parseInt(strings[2]));
        return node;
    }

    @Override
    public String toString() {
        return ip + ":" + port + ":" + taskCounts;
    }

    public void addCount() {
        this.taskCounts++;
    }

    public void completeCount() {
        this.taskCounts--;
    }

    public String getEndpoints() {
        return ip + ":" + port;
    }
}
